<{extend name="public/base"}>
<{block name="foot_source"}>
<script type="text/javascript" src="/static/webuploader/webuploader.js"></script>
<link rel="stylesheet" type="text/css" href="/static/webuploader/webuploader.css">
<{/block}>
<{block name="content"}>
<!-- left column -->
<div class="col-md-12">
    <!-- general form elements -->
    <div class="box box-primary">
        <div class="box-header with-border">
            <h3 class="box-title"><{$title}></h3>
        </div>
        <!-- /.box-header -->
        <!-- form start -->
        <form role="form" action="<{:url('admin/role/handlePermission')}>" method="post" id="form">
            <div class="box-body">
                <div class="form-group">
                    <label >角色名称</label>
                    <span><{$model.title}></span>
                </div>

            </div>
            <div class="box-body" id="already_have">
                <div><label>当前拥有的权限</label></div>
                <?php foreach($model->permission as $key => $val ){ ?>
                <span class="btn btn-default btn-sm" data-id="<?php echo $permissions[$val]['id']; ?>" title="<?php echo $permissions[$val]['url'] ?>"><?php echo $permissions[$val]['title']; ?></span>
                <?php } ?>
            </div>
            <div class="box-body">
                <div><label>权限列表</label></div>
                <?php foreach($group as $key => $val){ ?>
                    <div style="margin-top:5px;">
                        <span><?php echo $key ?>: </span>
                        <?php foreach($val as $k => $v ){ ?>
                        <span class="btn btn-default btn-sm permission-list" data-id="<?php echo $v['id'];?>" data-title="<?php echo $v['title']; ?>" data-url="<?php echo $v['url']; ?>" title="<?php echo $v['url'] ?>"><?php echo $v['title']; ?></span>
                        <?php } ?>
                    </div>
                <?php } ?>
            </div>
            <!-- /.box-body -->
            <input type="hidden" name="id" value="<{$model.id}>" />
            <div class="box-footer">
                <a href="javascript:;" class="btn btn-primary" id="submit">提交</a>
                <a href="<{:url('admin/role/index')}>" class="btn btn-warning ">返回列表</a>
            </div>
        </form>
    </div>
    <!-- /.box -->
</div>
<{/block}>
<{block name="foot_script"}>
    <script type="text/javascript">
        $(".permission-list").click(function(){
            var id = $(this).data('id');
            var title = $(this).data('title');
            var url = $(this).data('url');
            $("#already_have").append("<span class=\"btn btn-default btn-sm\" data-id='"+id+"' title='"+url+"'>"+title+"</span> ");
        });
        $("#submit").click(function(){
            $("#already_have span").each(function(index,item){
                var id = $(item).data('id');
                $('#form').append("<input type='hidden' value='"+id+"' name='permission[]' />");
                $("#form").submit();
            });
        });
        $("#already_have").delegate("span","click",function(){
            $(this).remove();
        });
    </script>
<{/block}>
<{block name="head_source"}>
    <style type="text/css">
        #already_have span{
            margin-top:5px;
        }
    </style>
<{/block}>
